var strUrl = location.href;
var indexUrlArr = ['addDetail.html','index.html','product.html'];
var cartUrlArr = ['cart.html'];
var myUrlArr = ['addAddress.html','address.html','detailList.html','my.html'];

function goFistPage(){
    window.location.href="/mobile/view/index.html";
}
function goMyPage(){
    window.location.href="/mobile/view/my.html";
}
function goCartPage(){
    window.location.href="/mobile/view/cart.html";
}
function getMemberId(){
    var memberData=$.getCache("member");
    var memberId = memberData.id;
    return memberId;
}
function inArr(indexUrlArr, strUrl) {
    if(indexUrlArr != null && indexUrlArr.length > 0) {
        for (var i=0;i<indexUrlArr.length;i++){
            if (strUrl.indexOf(indexUrlArr[i]) != -1) {
                return true;
            }
        }
    }
}
function checkLogin(callback){
    var memberId = getMemberId();
    if(!memberId){
        $.login({
            title: '登录',
            username: '',  // 默认用户名
            password: '',  // 默认密码
            onOK: function (username, password) {
                //点击确认
                $.showLoading("正在提交中");
                $.post(baseURL + "api/member/login", {
                    "phone": username,
                    "password": password
                }, function (result) {
                    if (0 == result.code) {
                        $.hideLoading();
                        $.setCache("member",result.member);
                        if (callback != null && typeof callback === "function"){
                            callback();
                        } else{
                            // 刷新当前页面
                            window.location.reload();
                        }
                        
                    } else {
                        $.hideLoading();
                        $.toast(result.msg, "text");
                    }
                })
            },
            onCancel: function () {
                //点击取消
            }
        });
    }else{
        if (callback != null && typeof callback === "function"){
            callback();
        }
    }
}